package pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 固定单线程解决，和FixThreadPool有类似之处
 * @author lcx
 *
 */
public class SingleThreadExecutorTest {

	public static void main(String[] args) {
		ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();  
		for (int i = 0; i < 100; i++) {  
			final int index = i;  
			singleThreadExecutor.execute(new Runnable() {  
				public void run() {  
					try {  
						System.out.println(index);  
						Thread.sleep(2000);  
					} catch (InterruptedException e) {  
						e.printStackTrace();  
					}  
				}  
			});  
		}  
	}  
}
